package web.activity;

import bean.Activity;
import bean.Department;
import com.alibaba.fastjson.JSON;
import entity.ActivityEntity;
import entity.DepartmentEntity;
import util.FANREN;

import javax.persistence.EntityManager;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ActivityDelete",urlPatterns = "/dao/update/activityDelete")
public class ActivityDelete extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String jsonString = FANREN.getJson(request);
        System.out.println(jsonString);
        EntityManager em = (EntityManager) request.getAttribute("_entity.Manager");
        Activity activity = JSON.parseObject(jsonString,Activity.class);
        ActivityEntity activityEntity = em.find(ActivityEntity.class,Integer.parseInt(activity.getAid()));
        if(activityEntity!=null)
            em.remove(activityEntity);
        //删除一条记录
    }
}
